﻿using Asp.Versioning;
using Himp.TaskScheduling.Samples;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Application.Dtos;

namespace Himp.TaskScheduling.V1
{
    /// <summary>
    /// 流程定义
    /// </summary>
    [Area(TaskSchedulingRemoteServiceConsts.ModuleName)]
    [RemoteService(Name = TaskSchedulingRemoteServiceConsts.RemoteServiceName)]
    [Route("api/taskScheduling/workflowDefinition")]
    [ApiVersion("1.0")]
    [ApiController]
    [ControllerName("workflowDefinition")]
    public class WorkflowDefinitionController : TaskSchedulingController, IWorkflowDefinitionService
    {
        private readonly IWorkflowDefinitionService _workflowDefinitionService;

        public WorkflowDefinitionController(IWorkflowDefinitionService workflowDefinitionService)
        {
            _workflowDefinitionService = workflowDefinitionService;
        }

        [HttpGet]
        public async Task<PagedResultDto<WorkflowModelDto>> GetListAsync([FromQuery] ProcessDefinitionInput input)
        {
            return await _workflowDefinitionService.GetListAsync(input);
        }

        /// <summary>
        /// 激活/挂起
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("activate")]
        public async Task<WorkflowInstanceStasDto> PostActivateAsync([FromBody] WorkflowActivateDto input)
        {
            WorkflowInstanceStasDto stasDto = new WorkflowInstanceStasDto();
            await _workflowDefinitionService.PostActivateAsync(input);

            return stasDto;
        }

        /// <summary>
        /// 部署
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("deploy")]
        public async Task<WorkflowInstanceStasDto> PostDeployAsync([FromBody] WorkflowDeployDto input)
        {
            WorkflowInstanceStasDto stasDto = new WorkflowInstanceStasDto();
            var res = await _workflowDefinitionService.PostDeployAsync(input);

            return stasDto;
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<WorkflowInstanceStasDto> DeleteAsync(string id)
        {
            WorkflowInstanceStasDto stasDto = new WorkflowInstanceStasDto();
            await _workflowDefinitionService.DeleteAsync(id);

            return stasDto;
        }
    }
}
